package com.sxc.loglib;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;


/**
 * Create by sunxunchao on 2019/9/17
 */
public class LogApp extends Application {

    @SuppressLint("StaticFieldLeak")
    private static Context mContext;

    public static Context getAPP() {
        return mContext;
    }

    public static void initialize(Context context) {
        mContext = context;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss", Locale.CHINA);
        String fileName = format.format(new Date(System.currentTimeMillis())) + ".log";
        LogConfig.getInstance()
                .isWriteLog(true)//是否在文件中记录，默认不记录
                .isSaveExternal(true) //默认保存在应用内
                .setFileName(fileName)
                .setSaveFileTime(24 * 60 * 60 * 1000)//设置清空日志的时间 默认是一天清理一次日志
                .setCrashName("crash_" + fileName)
                .setFolderName("study")
                .fileSize(100 * 1024)//日志文件的大小，默认0.1M,以bytes为单位
                .setUseShake(true)
                .build(this)
                .start();
    }
}
